#!/bin/bash

#COMANDOS
CMD_CAT=$(type -p cat)
CMD_GREP=$(type -p grep)
CMD_AWK=$(type -p awk)
CMD_WGET=$(type -p wget)
CMD_MV=$(type -p mv)
CMD_MYSQL=$(type -p mysql)
CMD_TAIL=$(type -p tail)
CMD_HEAD=$(type -p head)
CMD_DU=$(type -p du)

#DATA DO LOG
DATALOG=$(/bin/date -d '0 day ago' +%Y-%m-%d)
DATAEMAIL=$(/bin/date -d '0 day ago' +%d-%m-%Y)

#DADOS PARA CONECTAR NO BANCO
APP_DB_USER=root
APP_DB_PASS=sun123
APP_DB_HOST=localhost
APP_DB_BASE=vmlogs

echo -n "
Caros,

Conforme monitor do dia ${DATAEMAIL} segue abaixo os servidores que ocupam o maior numero de espaco no NFS, poderiam verificar o que conseguem diminuir?

" > /tmp/vmlogs_alert.msg_tmp

${CMD_MYSQL} -u ${APP_DB_USER} -p${APP_DB_PASS} -D ${APP_DB_BASE} -s -e "SELECT servidores.nome_host, servidores.equipe, servidores_logs.particao, servidores_logs.tamanho FROM servidores_logs, servidores WHERE servidores_logs.data_insercao = '${DATALOG}' AND servidores_logs.nome_host = servidores.id ORDER BY tamanho DESC limit 15" | sed 's/AC/CORP/g' |sed 's/ EM / EMAIL /g' |awk '{ if ( $3 == "0" ) print $1"\t\t"$2"\t\t""/export/logs""\t\t"$4" bytes" ; else print $1"\t\t"$2"\t\t""/export/logs_gz""\t\t"$4" bytes" ; }' >> /tmp/vmlogs_alert.msg_tmp

echo -n "
Mais informacoes em: http://app.portal.intranet/vmlogs/

Att,

Equipe de Alta Audiencia.
" >> /tmp/vmlogs_alert.msg_tmp

mail -s "VMlogs Monitor - ${DATAEMAIL}" l-tec-alta-audiencia\@uolinc.com < /tmp/vmlogs_alert.msg_tmp
mail -s "VMlogs Monitor - ${DATAEMAIL}" l-tec-ecommerce\@uolinc.com < /tmp/vmlogs_alert.msg_tmp
mail -s "VMlogs Monitor - ${DATAEMAIL}" l-tec-sistemas-base\@uolinc.com < /tmp/vmlogs_alert.msg_tmp
mail -s "VMlogs Monitor - ${DATAEMAIL}" l-adm-corp-n2\@uolinc.com < /tmp/vmlogs_alert.msg_tmp
mail -s "VMlogs Monitor - ${DATAEMAIL}" l-adm-mail-n2\@uolinc.com < /tmp/vmlogs_alert.msg_tmp

rm /tmp/vmlogs_alert.msg_tmp
